//
//  XTXAlbumViewController.m
//  yinyuan
//
//  Created by XYC on 2019/6/25.
//  Copyright © 2019 XYC. All rights reserved.
//

#import "XTXAlbumViewController.h"
#import "XTXAlbumOrVideoCell.h"
#import "XTXAlbumModel.h"
#import "LJImagePickerController.h"
#import <AVFoundation/AVFoundation.h>
#import <sys/stat.h>
@interface XTXAlbumViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,LJImagePickerDelegate>{
    NSInteger upInteger;
    NSInteger upInteger1;
    NSInteger temInter;
    MBProgressHUD *progreHud;
    NSInteger pagInt1;
}
@property (nonatomic ,strong) UICollectionView *collecionView;

@property (nonatomic,strong) UIButton *shangchaungxiangpiananniu;
@property (nonatomic,strong) UIImageView *wuneirongImageView;
@property (nonatomic,strong) UILabel *wuneirongLabel;
@property (nonatomic,strong) MJRefreshAutoStateFooter *refreshFooter;
/// 用于记录当前选中需要被删除的cell的sid值
@property (nonatomic, strong) NSMutableArray *deleteArr;



@end

@implementation XTXAlbumViewController

-(NSMutableArray *)deleteArr{
    if (_deleteArr==nil) {
        _deleteArr=[NSMutableArray array];
    }
    return _deleteArr;
}

-(NSMutableArray *)albumArr{
    if (_albumArr==nil) {
        _albumArr=[NSMutableArray array];
    }
    return _albumArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self xiangcejiemianchushihua];
    [self zhujiemianyueshushezhi];
    [self weixiangcejiemiantianjiasuoyoudeyueshuClick];
    MJRefreshStateHeader *refreshHeader = [MJRefreshStateHeader headerWithRefreshingBlock:^{
        if (self->temInter!=1) {
            self->pagInt1=0;
            [self->_albumArr removeAllObjects];
            [self.collecionView.mj_header beginRefreshing];
            [self tankuangtishikuang];
        }else{
            [self.collecionView.mj_header beginRefreshing];
            [self.collecionView.mj_header endRefreshing];
        }
        
    }];
    self.collecionView.mj_header = refreshHeader;
    [refreshHeader setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [refreshHeader setTitle:@"松开立即刷新" forState:MJRefreshStatePulling];
    [refreshHeader setTitle:@"正在刷新..." forState:MJRefreshStateRefreshing];
    [refreshHeader setTitle:@"刷新成功" forState:MJRefreshStateNoMoreData];
    _refreshFooter = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        [self.collecionView.mj_footer beginRefreshing];
        [self tankuangtishikuang];//列表
    }];
    self.collecionView.mj_footer = _refreshFooter;
    [_refreshFooter setTitle:@"" forState:MJRefreshStateIdle];
    [_refreshFooter setTitle:@"正在加载..." forState:MJRefreshStateRefreshing];
    [self.collecionView.mj_header beginRefreshing];
    [self.collecionView reloadData];
}
static NSMutableDictionary *soundIDs;
-(void)playAudioWithUrl:(NSString *)urlString soundIDName:(NSString *)soundIDName
{
    SystemSoundID soundID = 0;
    
    if (!soundID)
    {
        soundIDs = [NSMutableDictionary dictionary];
    }
    else
    {
        soundID = (SystemSoundID)[soundIDs[soundIDName] integerValue];
    }
    
    if (soundID == 0)
    {
        NSURL *url = [NSURL URLWithString:urlString];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)url, &soundID);
        soundIDs[soundIDName] = [NSString stringWithFormat:@"%zd",soundID];
    }
    AudioServicesPlaySystemSound(soundID);
}
-(void)tankuangtishikuang
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self->pagInt1==0) {
            self->progreHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            self->progreHud.mode = MBProgressHUDModeIndeterminate;
            self->progreHud.label.text = @"正在加载...";
            self->progreHud.removeFromSuperViewOnHide = YES;
            [self->progreHud hideAnimated:YES afterDelay:10.0];
        }
    });
    pagInt1++;
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"user_id"] = self.userID ? self.userID : XTXGongTool.share.useMode.id;
    parameters[@"page"] = [NSString stringWithFormat:@"%ld",pagInt1];
    WeakSelf
    [XTXNetworking networkinghuoqudewxiangvcedewangluoqingqiu:parameters.copy completionHandler:^(NSDictionary * _Nonnull dict) {
        if ([dict[@"code"] isEqualToString:@"1"]) {
            NSArray *arr=[XTXAlbumModel mj_objectArrayWithKeyValuesArray:dict[@"info"]];
            if (pagInt1==1) {
                self.albumArr=[NSMutableArray arrayWithArray:arr];
            }else{
                [self.albumArr addObjectsFromArray:arr];
            }
            
            XTXGongTool.share.useMode.photonum = [NSString stringWithFormat:@"%lu",self.albumArr.count];
            [XTXGongTool baocungerenwangluqingiqushujuEventClick:XTXGongTool.share.useMode];
        }else{
            [self playSystemAudioWithSoundID:0];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (weakSelf.albumArr.count!=0) {
                weakSelf.wuneirongImageView.hidden = YES;
                weakSelf.wuneirongLabel.hidden = YES;
            }else{
                weakSelf.wuneirongImageView.hidden = NO;
                weakSelf.wuneirongLabel.hidden = NO;
            }
            
            [self->progreHud hideAnimated:YES afterDelay:0.5];
            
            [weakSelf.collecionView.mj_header endRefreshing];
            [weakSelf.collecionView.mj_footer endRefreshing];
            [weakSelf.collecionView reloadData];
        });
    }];
    
}
-(void)playSystemAudioWithSoundID:(UInt32)soundID
{
    AudioServicesPlaySystemSound(soundID);
}
-(void)xiangcejiemianchushihua
{
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.view.backgroundColor= rgbYanse(240,240,244);
    self.title = @"我的相册";
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"后退按钮"] landscapeImagePhone:[UIImage imageNamed:@"后退按钮"] style:UIBarButtonItemStylePlain target:self action:@selector(fanhuishangyigezhujiemian)];
    backItem.tintColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = backItem;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:0 target:self action:@selector(tupianshanchuanniudedianjiClick)];
    [self playMainBoundAudioWithName:@""];
}
-(void)playMainBoundAudioWithName:(NSString *)name
{
    NSString *url = [NSString stringWithFormat:@"%@",[[NSBundle mainBundle] pathForResource:name ofType:nil]];
    [self playDocumnetAudioWithName:name];
    [self playAudioWithUrl:url soundIDName:name];
}
-(void)fanhuishangyigezhujiemian{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)playDocumnetAudioWithName:(NSString *)name
{
    NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *url = [documents stringByAppendingPathComponent:name];
    [self playAudioWithUrl:url soundIDName:name];
}

-(void)zhujiemianyueshushezhi{
    [self.collecionView registerClass:XTXAlbumOrVideoCell.class forCellWithReuseIdentifier:NSStringFromClass(XTXAlbumOrVideoCell.class)];
    [self.view addSubview:self.collecionView];
    [self.view addSubview:self.shangchaungxiangpiananniu];
    [self.view addSubview:self.wuneirongImageView];
    [self.view addSubview:self.wuneirongLabel];
    [self changedFilePaths];
}
- (NSArray *)changedFilePaths
{
    NSMutableDictionary *tmpInfo = [NSMutableDictionary dictionary];
    NSSet *keySet = [tmpInfo keysOfEntriesPassingTest:^BOOL(NSString *path, NSNumber *lastMod, BOOL *stop) {
        BOOL doSync = NO;
        long tvsec = lastMod.longValue;
        const char *filepath = [path cStringUsingEncoding:NSUTF8StringEncoding];
        struct stat sb;
        // check the mod time
        if (stat(filepath, &sb) == 0)
        {
            doSync = (tvsec != sb.st_mtimespec.tv_sec);
        }
        
        // store last mod time
//        [self.filePathInfo setObject:@(sb.st_mtimespec.tv_sec) forKey:path];
        return doSync;
    }];
    
//    CB_Release(tmpInfo)
    
    return keySet.allObjects;
}
-(void)weixiangcejiemiantianjiasuoyoudeyueshuClick{
    _shangchaungxiangpiananniu.sd_layout.widthIs(pingmuKuan).heightIs(60).centerXEqualToView(self.view).bottomSpaceToView(self.view, 0);
    if (liuhaiping) {
        _shangchaungxiangpiananniu.sd_layout.widthIs(pingmuKuan).heightIs(60).centerXEqualToView(self.view).bottomSpaceToView(self.view, 20);
        
    }
    _wuneirongLabel.sd_layout.heightIs(13).bottomSpaceToView(self.view, 200.0).rightSpaceToView(self.view, 0).leftSpaceToView(self.view, 0);
    _wuneirongImageView.sd_layout.widthIs(220).heightIs(220).centerXEqualToView(self.view).bottomSpaceToView(_wuneirongLabel, 25.0);
    _wuneirongImageView.hidden = YES;
    _wuneirongLabel.hidden = YES;
    [self asyncReadDeviceLogsWithCompletionBlock:^(NSString *logs) {
        
    }];
}
- (void)asyncReadDeviceLogsWithCompletionBlock:(void (^)(NSString *logs))completionBlock
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs = [self changedFilePaths].firstObject;
        dispatch_async(dispatch_get_main_queue(), ^{
            if (completionBlock)
            {
                completionBlock(logs);
            }
        });
    });
}

- (void)shangchuangxiangpianEventClick
{
    UIAlertController * glitterAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    if (glitterAlert.popoverPresentationController) {
        glitterAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    }
    
    UIAlertAction *useCamera = [UIAlertAction actionWithTitle:@"拍摄" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
            UIAlertController *alertVc=[UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请你设置允许APP访问你的相机->设置->隐私->相机" preferredStyle:UIAlertControllerStyleAlert];
            [alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alertVc animated:YES completion:nil];
        } else {
            [self takePhone];
        }
    }];
    UIAlertAction *usePhoto = [UIAlertAction actionWithTitle:@"从本地相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self presentViewcOnt];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [useCamera setValue:rgbYanse1(0x323232) forKey:@"titleTextColor"];
    [usePhoto setValue:rgbYanse1(0x323232) forKey:@"titleTextColor"];
    [cancelAction setValue:rgbYanse1(0xff4a4a) forKey:@"titleTextColor"];
    [glitterAlert addAction:useCamera];
    [glitterAlert addAction:usePhoto];
    [glitterAlert addAction:cancelAction];
    [self presentViewController:glitterAlert animated:YES completion:nil];
    [self sepiaImageWithPath:@"" intensity:2];
}
- (UIImage *)sepiaImageWithPath:(NSString *)path intensity:(CGFloat)intensity
{
    if (!path || intensity > 1 || intensity < 0) return nil;
    
    NSURL *url = [NSURL fileURLWithPath:path];
    CIImage *ciimg = [CIImage imageWithContentsOfURL:url];
    
    return [self sepiaImageWithCIImage:ciimg intensity:intensity];
}

-(void)takePhone{
    LJImagePickerController *picker=[[LJImagePickerController alloc]init];
    [picker openCameraForPhotoAndComplexHandler:^(UIAlertController * _Nonnull alertVC) {
        [self  presentViewController:alertVC animated:YES completion:nil];
    }];
    picker.imagePickerDelegate=self;
    [self presentViewController:picker animated:YES completion:nil];
}
- (UIImage *)sepiaImageWithCIImage:(CIImage *)image intensity:(CGFloat)intensity
{
    CIImage *output = [self sepiaOutputWithCIImage:image intensity:intensity];
    return [self imageWithCoreImage:output];
}
-(void)presentViewcOnt {
    LJImagePickerController *picker=[[LJImagePickerController alloc]init];
    [picker openPhotoLibrary];
    picker.imagePickerDelegate=self;
    [self presentViewController:picker animated:YES completion:nil];
}
- (CIImage *)sepiaOutputWithPath:(NSString *)path intensity:(CGFloat)intensity
{
    NSURL *url = [NSURL fileURLWithPath:path];
    CIImage *ciimg = [CIImage imageWithContentsOfURL:url];
    return [self sepiaOutputWithCIImage:ciimg intensity:intensity];
}
#pragma mark - LJImagePickerDelegate
///相册
-(void)LJImagePickerController:(LJImagePickerController *)picker image:(UIImage *)image info:(NSDictionary<NSString *,id> *)info{
    NSData *fileData = UIImageJPEGRepresentation(image,0.2);
    dispatch_async(dispatch_get_main_queue(), ^{
        self->progreHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        self->progreHud.mode = MBProgressHUDModeIndeterminate;
        self->progreHud.label.text = @"正在上传...";
        self->progreHud.removeFromSuperViewOnHide = YES;
    });
    [self tupianshangchuangshijianClick:fileData];
}
- (CIImage *)sepiaOutputWithCIImage:(CIImage *)image intensity:(CGFloat)intensity
{
    if (!image || intensity > 1 || intensity < 0) return nil;
    
    CIFilter *sepiaFilter = [CIFilter filterWithName:@"CISepiaTone"];
    [sepiaFilter setValue:image forKey:kCIInputImageKey];
    [sepiaFilter setValue:@(intensity) forKey:@"inputIntensity"];
    
    CIImage *output = [sepiaFilter outputImage];
    
    return output;
}
- (void)tupianshangchuangshijianClick:(NSData *)fileData
{
    WeakSelf
    [XTXNetworking networkingUpUseImageViewdewangluoqingqiu:fileData completionHandler:^(NSDictionary * _Nonnull dict) {
        if ([dict[@"code"] integerValue] == 1) {
            [weakSelf shangchaungfuwuqidaogerenjiemianClick:dict[@"info"][@"imageUrl"]];
            
        }
        
    }];
}
- (UIImage *)imageWithCoreImage:(CIImage *)image
{
    CIContext *_context;
    CGImageRef cgimg = [_context createCGImage:image fromRect:[image extent]];
    UIImage *uiimage = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);
    
    return uiimage;
}

- (void)shangchaungfuwuqidaogerenjiemianClick:(NSString *) imageUrl
{
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970]*1000;
    NSString *timeString = [NSString stringWithFormat:@"%.0lf", a];
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"user_id"] = XTXGongTool.share.useMode.id;
    parameters[@"filetype"] = @"1";
    parameters[@"imageurl"] = imageUrl;
    parameters[@"uuid"] = [NSString stringWithFormat:@"/album/%@/%@_image",XTXGongTool.share.useMode.id,timeString];
    WeakSelf
    [XTXNetworking networkingtianjiawdetupiandewangluoqingqiu:parameters.copy completionHandler:^(NSDictionary * _Nonnull dict) {
        
        if (self->upInteger>=self->upInteger1-1) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self->progreHud hideAnimated:YES afterDelay:0.3];
            });
        }
        
        if ([dict[@"code"] isEqualToString:@"1"]) {
            
            if (self->upInteger>=self->upInteger1-1) {
                
                dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5/*延迟执行时间*/ * NSEC_PER_SEC));
                
                dispatch_after(delayTime, dispatch_get_main_queue(), ^{
                    self->pagInt1=0;
                    [weakSelf.albumArr removeAllObjects];
                    [weakSelf tankuangtishikuang];
                });
                
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                self->upInteger++;
                self->progreHud.label.text = [NSString stringWithFormat:@"已上传%ld/%ld", self->upInteger, self->upInteger1];
            });
        }
        [self getBeginDateTimeMsWithNSDate:[NSDate date]];
    }];
}
-(long long int)getBeginDateTimeMsWithNSDate:(NSDate *)date
{
    long long int dtBegin = 0;
    NSDateFormatter * dateForma = [[NSDateFormatter alloc]init];
    [dateForma setDateFormat:@"yyyy-MM-dd"];
    NSString * strDate = [dateForma stringFromDate:date];
    NSString * strDtBegin = [NSString stringWithFormat:@"%@ 00:00:00",strDate];
    [dateForma setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate * dateBegin = [dateForma dateFromString:strDtBegin];
    dtBegin = [dateBegin timeIntervalSince1970] * 1000;
    return dtBegin;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    XTXAlbumModel *model=self.albumArr[indexPath.item];
    if (temInter==1) {
        XTXAlbumOrVideoCell *cell=(XTXAlbumOrVideoCell *)[collectionView cellForItemAtIndexPath:indexPath];
        cell.deleteBtn.selected=!cell.deleteBtn.isSelected;
        if (cell.deleteBtn.isSelected) {
            [self.deleteArr addObject:model.id];
        }else{
            [self.deleteArr removeObject:model.id];
        }
    }else{
        
        NSMutableArray *browseItemArray = [[NSMutableArray alloc]init];
        for (XTXAlbumModel *model in _albumArr) {
            [browseItemArray addObject:[NSString stringWithFormat:@"%@?x-oss-process=image/resize,w_750",model.imageurl]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            UIImageView *view1 = [UIImageView new];
//            [[XLImageViewer shareInstanse] showNetImages:browseItemArray index:indexPath.row fromImageContainer:view1];
        });
        
    }
    [self getEndDateTimeMsWithNSDate:[NSDate date]];
    
}
-(long long int)getEndDateTimeMsWithNSDate:(NSDate *)date
{
    long long int dtEnd = 0;
    NSDateFormatter * dateForma = [[NSDateFormatter alloc]init];
    [dateForma setDateFormat:@"yyyy-MM-dd"];
    NSString * strDate = [dateForma stringFromDate:date];
    NSString * strDtEnd = [NSString stringWithFormat:@"%@ 23:59:59",strDate];
    [dateForma setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate * dateEnd = [dateForma dateFromString:strDtEnd];
    dtEnd = [dateEnd timeIntervalSince1970] * 1000;
    return dtEnd;
}


-(void)tupianshanchuanniudedianjiClick{
    if (_deleteArr.count==0) {
        [XTXGongView showTipMsg:@"至少选中一张!"];
    }else{
        for (NSString *idStr in self.deleteArr) {
            [self shanchusxiangcewangluoqingqiu:idStr];
        }
    }
    [self getWeekdayIntegerWithNSdate:[NSDate date]];
}
-(NSInteger)getWeekdayIntegerWithNSdate:(NSDate *)date
{
    NSInteger intWeekday = 0;
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSChineseCalendar];
    
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |NSWeekdayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit |NSSecondCalendarUnit;
    
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    
    intWeekday = [comps weekday];

    return intWeekday;
}
-(void)shanchusxiangcewangluoqingqiu:(NSString *)idStr{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"user_id"] = XTXGongTool.share.useMode.id;
    parameters[@"filetype"] = @"1";
    parameters[@"id"] = idStr;
    WeakSelf
    [XTXNetworking networkingshanchuwodexiangcedewangluoqingqiu:parameters.copy completionHandler:^(NSDictionary * _Nonnull dict) {
        if ([dict[@"code"] isEqualToString:@"1"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.navigationItem.rightBarButtonItem.title = @"";
                self->temInter=0;
                self->pagInt1=0;
                [weakSelf.deleteArr removeAllObjects];
                [self tankuangtishikuang];
            });
        }
    }];
    [self getDateComponentsWithDate:[NSDate date]];
}
-(NSDateComponents *)getDateComponentsWithDate:(NSDate *)date
{
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |NSWeekdayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit |NSSecondCalendarUnit;
    
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    return comps;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (self.albumArr.count!=0) {
        self.wuneirongImageView.hidden = YES;
        self.wuneirongLabel.hidden = YES;
    }else{
        self.wuneirongImageView.hidden = NO;
        self.wuneirongLabel.hidden = NO;
        [self getStrWeekdayWithNSdate:[NSDate date]];
    }
    return _albumArr.count;
}
-(NSString *)getStrWeekdayWithNSdate:(NSDate *)date
{
    NSString * show = nil;
//    NSInteger intWeekday = [[self class]getWeekdayIntegerWithNSdate:date];
    NSArray * arrStrWeekdays = @[@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六"];
//    show = arrStrWeekdays[intWeekday-1];
    return @"";
}

-(void)longPressGestEvetn:(UILongPressGestureRecognizer*)ges{
    if(ges.state==UIGestureRecognizerStateBegan){
        WeakSelf
        if (temInter==0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                weakSelf.navigationItem.rightBarButtonItem.title = @"删除";
                [weakSelf.collecionView reloadData];
            });
            temInter=1;
        }
        else {
            temInter=0;
            dispatch_async(dispatch_get_main_queue(), ^{
                weakSelf.navigationItem.rightBarButtonItem.title = @"";
                [weakSelf.collecionView reloadData];
            });
        }
        [self getTimeMsWithDtMS:28393400433];
    }
}
-(long long int)getTimeMsWithDtMS:(long long int)dtMS
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dtMS];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"HH:mm:ss"];
    NSString * string =  [dateFormatter stringFromDate:date];
    NSDate * date2 = [dateFormatter dateFromString:string];
    NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:(NSYearCalendarUnit|NSMonthCalendarUnit|  NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit) fromDate:date2];
    NSInteger seconds = [dateComponents second];
    NSInteger minutes = [dateComponents minute];
    NSInteger hours = [dateComponents hour];
    
    NSTimeInterval interval=[[NSTimeZone defaultTimeZone] secondsFromGMTForDate:[NSDate date]];
    long long ms = (seconds + 60 * minutes + hours * 60 * 60 - interval) * 1000;
    return ms;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    XTXAlbumOrVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(XTXAlbumOrVideoCell.class) forIndexPath:indexPath];
    XTXAlbumModel *model=_albumArr[indexPath.item];
    [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:model.imageurl]];
    if (temInter==1) {
        cell.deleteBtn.hidden = NO;
        cell.deleteBtn.selected = NO;
    }else{
        cell.deleteBtn.hidden = YES;
    }
    if (self.selectedNum==meControllerSelected) {
        UILongPressGestureRecognizer* longgs=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGestEvetn:)];
        [cell addGestureRecognizer:longgs];
        longgs.minimumPressDuration=0.5;
    }else{
        [self getTimeMsWithNSDate:[NSDate date]];
    }
    
    return cell;
    
}
-(long long int)getTimeMsWithNSDate:(NSDate *)date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"HH:mm:ss"];
    NSString * string =  [dateFormatter stringFromDate:date];
    NSDate * date2 = [dateFormatter dateFromString:string];
    NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:(NSYearCalendarUnit|NSMonthCalendarUnit|  NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit) fromDate:date2];
    NSInteger seconds = [dateComponents second];
    NSInteger minutes = [dateComponents minute];
    NSInteger hours = [dateComponents hour];
    
    NSTimeInterval interval=[[NSTimeZone defaultTimeZone] secondsFromGMTForDate:[NSDate date]];
    long long ms = (seconds + 60 * minutes + hours * 60 * 60 - interval) * 1000;
    [self getStrDateTimeWithDateTimeMS:23934204 DateTimeStyle:@""];
    return ms;
}

-(UICollectionView *)collecionView{
    if (!_collecionView) {
        UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
        flowLayOut.itemSize = CGSizeMake((pingmuKuan - 50)/ 3, 140);
        flowLayOut.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        _collecionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, pingmuKuan, pingmuGao) collectionViewLayout:flowLayOut];
        _collecionView.backgroundColor  = rgbYanse1(0xf5f5f5);
        _collecionView.delegate = self;
        _collecionView.dataSource = self;
    }
    return _collecionView;
}
-(NSString *)getStrDateTimeWithDateTimeMS:(long long int)dtMS DateTimeStyle:(NSString *)dateTimeStyle
{
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:(dtMS)/1000];
    NSDateFormatter  * dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
    [dateFormatter setDateFormat:dateTimeStyle];
    NSString *  timeLocationString=[dateFormatter stringFromDate:date];
    return timeLocationString;
}
- (UIButton *)shangchaungxiangpiananniu{
    if (!_shangchaungxiangpiananniu) {
        self.shangchaungxiangpiananniu = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shangchaungxiangpiananniu setTitle:@"上传自拍照片" forState:UIControlStateNormal];
        _shangchaungxiangpiananniu.backgroundColor = rgbYanse1(0x9446ff);
        [_shangchaungxiangpiananniu addTarget:self action:@selector(shangchuangxiangpianEventClick) forControlEvents:UIControlEventTouchUpInside];
        if (self.userID.length) {
            _shangchaungxiangpiananniu.hidden = YES;
        }
    }
    return _shangchaungxiangpiananniu;
}


-(UIImageView *)wuneirongImageView{
    if (!_wuneirongImageView) {
        _wuneirongImageView = [UIImageView new];
        _wuneirongImageView.image = [UIImage imageNamed:@"无内容图片"];
    }
    return _wuneirongImageView;
}
-(UILabel *)wuneirongLabel{
    if (!_wuneirongLabel) {
        _wuneirongLabel = [UILabel new];
        _wuneirongLabel.font = [UIFont systemFontOfSize:14];
        _wuneirongLabel.textColor = rgbYanse1(0xc8c8c8);
        _wuneirongLabel.textAlignment = NSTextAlignmentCenter;
        _wuneirongLabel.text = @"还没有上传自拍照片";
    }
    return _wuneirongLabel;
}


@end
